package com.health.security;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;

/**
 * @author: zipeng Li
 * 2021/6/12  21:40
 */
@Data
@TableName("sys_admin")
public class Admin implements UserDetails, Serializable {
    //主键自动增长
    @TableId(type = IdType.AUTO)
    private Long id;
    //登录名
    private String username;
    //登录密码，密码需要加密
    private String password;
    //由于authorities不是数据库里面的字段，所以要排除它，不然mybatis-plus找不到该字段会报错
    @TableField(exist = false)
    Collection<? extends GrantedAuthority> authorities;
    //帐户是否被锁定(1 未锁定，0已锁定)
    private boolean isAccountNonLocked;
    //创建时间
    @TableField(fill = FieldFill.INSERT)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;
    //更新时间
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;
    //是否是管理员 1：是 0 ：不是
    private String isAdmin;

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}

